﻿using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
using System.Collections;

namespace InsertFromSkyDrive
{
    [Serializable]
    public class PluginSettings
    {
        Hashtable m_properties = new Hashtable();

        private const string AUTOSIGNIN = "AUTOSIGNIN";
        private const string CID = "CID";
        private const string USER = "USER";

        public PluginSettings(IProperties properties)
        {
            Load(properties);
        }

        public bool Dirty { get; protected set; }

        public bool AutoSignIn
        {
            get { return (bool) m_properties[AUTOSIGNIN]; }
            set
            {
                Dirty = true;
                m_properties[AUTOSIGNIN] = value;
            }
        }

        public string CId
        {
            get { return (string) m_properties[CID]; }
            set
            {
                Dirty = true;
                m_properties[CID] = value;
            }
        }

        public string User
        {
            get { return (string) m_properties[USER]; }
            set
            {
                Dirty = true;
                m_properties[USER] = value;
            }
        }

        void Load(IProperties properties)
        {
            m_properties[AUTOSIGNIN] = properties.GetBoolean(AUTOSIGNIN, false);
            m_properties[CID] = properties.GetString(CID, "");
            m_properties[USER] = properties.GetString(USER, "");
        }

        public void Save(IProperties properties)
        {
            if (Dirty)
            {
                properties.SetBoolean(AUTOSIGNIN, (bool)m_properties[AUTOSIGNIN]);
                properties.SetString(CID, (string)m_properties[CID]);
                properties.SetString(USER, (string)m_properties[USER]);
            }
        }
    }
}
